﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CE.HR;

public partial class HR_hr_create : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Params["hrid"] != null)
            {
                Int64 _hrid = Int64.Parse(Request.Params["hrid"].ToString());
                HRAccount _hraccount = new HRAccount();
                HRAccountDB _hraccountdb = new HRAccountDB();
                _hraccount = _hraccountdb.GetAccount(_hrid);

                txtName.Text = _hraccount.Name;
                txtEmail.Text = _hraccount.Email;
                txtPassword.Text = _hraccount.AuthCode;
                ddlCountry.SelectedValue = _hraccount.Country;
                btnCreate.Text = "Update";

                lblTitle.Text = "Edit User";
            }
            else
            {
                lblTitle.Text = "Create New User";
            }
        }
    }
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            HRAccount _hraccount = new HRAccount();
            HRAccountDB _hraccountdb = new HRAccountDB();

            if (Request.Params["hrid"] != null)
            {
                Int64 _hrid = Int64.Parse(Request.Params["hrid"].ToString());
                 _hraccount = _hraccountdb.GetAccount(_hrid);
            }
            else
            {
                _hraccount.HRTypeId = 100;
                _hraccount.Status = true;
                _hraccount.RefHRID = 0;
            }
            _hraccount.Name = txtName.Text;
            _hraccount.Email = txtEmail.Text;
            _hraccount.AuthCode = txtPassword.Text;
            _hraccount.Country = ddlCountry.SelectedValue;

            Int64 _result = _hraccountdb.InsertUpdate(_hraccount);

            if (_result > 0)
                Response.Redirect("hr-list.aspx");
        }
    }
}
